#!/bin/bash

bakdir=/var/backup/

#判断目录存在
if [ ! -d "$bakdir" ];then
  mkdir "$bakdir"
fi

journal=/var/jour/
if [ ! -d "$journal" ];then
  mkdir "$journal"
fi


time=`date ’+%Y-%m-%d-%H:%m’`


target=$1

if [ ! -d "$target" ];then
  echo ”The file path wrong!”
  exit 1
else
  tarFile=${bakdir}${time}”.tar.gz”
  tar –zcvf “tarFile” “$target”
  echo “backup done”

#添加日志
   jouFile=${journal}${time}".txt"
   touch "$jouFile"
   echInfor=${time}" backup target "${target}" to "${tarFile}
   echo "$echInfor"
   echo "$echInfor" >> "$jouFile"
fi
